import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;
import java.util.Map;

/**
 * 基于UDP的字典服务
 */
public class UDPDictServer extends UDPEchoSever{
    private Map<String,String> map;
    //初始化
    public UDPDictServer(int port) throws SocketException {
        super(port);
        map = new HashMap<>();
        map.put("tiger","老虎");
        map.put("cat","猫");
        map.put("dog","狗");
        map.put("pig","猪");
    }

    @Override
    protected String process(String key) {
        String s = map.getOrDefault(key,"查无此词...");
        return s;
    }

    public static void main(String[] args) throws IOException {
        UDPDictServer udpDictServer = new UDPDictServer(8888);
        udpDictServer.start();
    }
}
